home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / mail110 / getcmd.c < prev    next >
C/C++ Source or Header  |  1994-02-25  |  5KB  |  160 lines

  1. //=========================================================
  2. //
  3. //      getcmd.c
  4. //
  5. //      COMMAND getcmd(int *msgno, char *xuser, char *xfile)
  6. //
  7. //      Prompt for a command and parse the user input.
  8. //
  9. //      Return any msgno, user, and file specified in msgno,
  10. //      xuser, xfile.
  11. //
  12. //      If no msgno given, set it to cmsg (current message).
  13. //      If no xfile or xuser given, set to NULL.
  14. //
  15. //=========================================================
  16.  
  17. // $Id: getcmd.c,v 1.3 1994/02/25 13:34:54 gbj Exp user $
  18.  
  19. /*
  20. $Log: getcmd.c,v $
  21.  * Revision 1.3  1994/02/25  13:34:54  gbj
  22.  * Tidy-up.
  23.  *
  24.  * Revision 1.2  1994/02/08  23:32:02  gbj
  25.  * First public release.
  26.  *
  27.  * Revision 1.1  1994/02/08  03:15:10  gbj
  28.  * Initial revision
  29.  *
  30. */
  31.  
  32. #include "mailer.h"
  33.  
  34. COMMAND getcmd(int *msgno, char *xuser, char *xfile)
  35. {
  36.         char *f1, *f2, *f3, *bp;
  37.         char buf[80];
  38.         char cmd, cmdstring[80];
  39.         
  40.         *msgno=cmsg;
  41.         *xuser='\0';
  42.         *xfile='\0';
  43.         
  44.         printf("%s>", user);
  45.         bp=fgets(buf, 79, stdin);       // I want the \n
  46.         if (*buf == '\n')               // Simulate \n entered only
  47.                 *buf='Z';               // for UNREAD command 
  48.  
  49.         if (bp == NULL)
  50.                 return BAD;
  51.                 
  52.         f1=strtok(buf, " \r\n");                // command
  53.         f2=strtok(NULL, " \r\n");               // first arg
  54.         f3=strtok(NULL, " \r\n");               // second arg
  55.         
  56.         if (f1 == NULL)
  57.                 return BAD;
  58.         if (*f1 == '\0')
  59.                 return BAD;
  60.                 
  61.         strcpy(cmdstring, f1);
  62.         cmd=cmdstring[0];
  63.         switch (cmd)
  64.         {
  65.                 case 'd':       
  66.                 case 'r':
  67.                 case 'u':
  68.                 case 'p':
  69.                 case 'h':
  70.                         if (f2)
  71.                                 if (*f2)
  72.                                         *msgno=atoi(f2);
  73.                                 else
  74.                                         *msgno=cmsg;
  75.                         else
  76.                                 *msgno=cmsg;
  77.                         break;
  78.                 case '0':
  79.                 case '1':
  80.                 case '2':
  81.                 case '3':
  82.                 case '4':
  83.                 case '5':
  84.                 case '6':
  85.                 case '7':
  86.                 case '8':
  87.                 case '9':
  88.                         *msgno=atoi(f1);
  89.                         break;
  90.                 case 'm':
  91.                         if (f2)
  92.                                 if (*f2)
  93.                                         strcpy(xuser, f2);
  94.                         break;
  95.                 case 't':
  96.                         if (f2)
  97.                                 if (*f2)
  98.                                         strcpy(xuser, f2);
  99.                         if (f3)
  100.                                 if (*f3)
  101.                                         strcpy(xfile, f3);
  102.                         break;
  103.                 case 'f':
  104.                         if (f2)
  105.                                 if (*f2)
  106.                                         strcpy(xuser, f2);
  107.                         if (f3)
  108.                                 if (*f3)
  109.                                         *msgno=atoi(f3);
  110.                                 else
  111.                                         *msgno=cmsg;
  112.                         break;
  113.                 case 's':
  114.                 case 'w':
  115.                 case 'n':
  116.                         if (f2)
  117.                                 if (*f2)
  118.                                         strcpy(xfile, f2);
  119.                         break;
  120.                 case 'Z':       break;
  121.                 case '?':       break;
  122.                 default:        break;
  123.         }
  124.         
  125.         switch (cmd)
  126.         {
  127.                 case 'd':       return DELETE;
  128.                 case 'm':       return MAIL;
  129.                 case 's':       return SAVE;
  130.                 case 'w':       return WRITE;
  131.                 case 't':       return MAILFILE;
  132.                 case 'r':       return REPLY;
  133.                 case 'f':       return FORWARD;
  134.                 case 'u':       return UNDELETE;
  135.                 case '+':       return NEXT;
  136.                 case '-':       return PREV;
  137.                 case 'p':       return PRINT;
  138.                 case 'h':       return HEADER;
  139.                 case 'l':       return LIST;
  140.                 case 'n':       return NEW;
  141.                 case 'x':       return QUITX;
  142.                 case 'q':       return QUIT;
  143.                 case '?':       return HELP;
  144.                 case 'Z':       return UNREAD;
  145.                 case '0':
  146.                 case '1':
  147.                 case '2':
  148.                 case '3':
  149.                 case '4':
  150.                 case '5':
  151.                 case '6':
  152.                 case '7':
  153.                 case '8':
  154.                 case '9':       return READ;
  155.                 default:        return BAD;
  156.         }
  157.         return BAD;
  158. }
  159.                 
  160.